<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function fn() {
      //局部变量或块级变量 没有let声明直接赋值的当全局变量来看
      num = 10  //当全局变量来看 强烈不允许
      return num
    }
    console.log(fn())//由于num是全局变量，所以里面可以打印
    console.log(num) //由于num是全局变量，所以外面可以打印，但是强烈不允许

    function fun(x, y) {
      //形参可以看做是函数的局部变量
      console.log(x) //输出1
    }
    fun(1, 2)
    // console.log(x)  //错误的，因为x是形参相当于局部变量

    console.log('-------------------------')

    let a = 10
    function fn1() {
      let a = 20
      function fun1() {
        let a = 30
        console.log(a)
      }
      fun1()
    }
    fn1() //30

    let b = 10
    function fn2() {
      let b = 20
      function fun2() {
        // let b = 30
        console.log(b)
      }
      fun2()
    }
    fn2() //20

    let c = 10
    function fn3() {
      // let c = 20
      function fun3() {
        // let c = 30
        console.log(c)
      }
      fun3()
    }
    fn3() //10

    console.log('-------------------------')




  </script>
</body>

</html>